/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function calTime(){
    var currentETime = new Date();
    var eTime = currentETime.getTime();
    $('#responseTime').html(eTime - sTime);
}
var sTime;
function startTime(){
    var currentSTime = new Date();
    sTime = currentSTime.getTime();
    $('#responseTime').html("<img src=\"./images/loader.gif\" />");
}

 

function loadBinIncoming(){
    $.blockUI();
    $.post("TriggerMailServlet",{
        action: "loadBinIncoming"
    },
    function(data){

        $('#binincominglist').html(data);

    },
    "html"

    );
//เรียกใช้ BlockUI
}
function show_maillist(){

    //$("#select3").option

    
    $.post(
        "MailListServlet",
        {
            action:"maillistselect",            
            mailgroup:$('#Grouplist').val()
        },
        function(data){
             $("#maillist").html(data);
        },

        "html"

        );
        

//                $("#select3").fcbkcomplete({
//                    json_url: "data.txt",
//                    addontab: true,
//                    maxitems: 20,
//                    height: 10,
//                    cache: true
//                });
             
//    $('#select3').append(new Option('Foo', 'foo', true, true));
//เรียกใช้ BlockUI
}
function sendmail(bin1,status1){
    var mail_list="";
    $('#maillist input[type="checkbox"]:checked').each(function() {
    mail_list=mail_list+","+$(this).val();
    });
    if(mail_list==""){
        alert("Please select email in check box");
    }else{
    var subject1=prompt("This mail will send out by your email address:"+$("#gmail").text()+"\n To:"+mail_list+"\nPlease enter email subject","FDB BIN REPORT");
    if (subject1!=null){
        $.blockUI();
        $.post("SendMailServlet",{
            sendmail: "sendmail",
            status:status1,
            binid:bin1,
            group:$("#Grouplist").val(),
            subject:subject1,
            gmail:$("#gmail").text(),
            selectlist:mail_list
        },
        function(data){

            if(data.success){
                alert("Success to send mail to mailist group");
            }else{
                alert("Error to send mail to mailist group ");
            }

        },
        "json"

        );
    }
    }
//เรียกใช้ BlockUI
}
function loadGrouplist(){
    $.blockUI();
    startTime();
    $("#Grouplist").html("<img src=\"./images/loader.gif\" />");
    $("#Grouplist").load("TriggerMailServlet?action=mailgrouplist").hide().fadeIn('slow');
    calTime();
//เรียกใช้ BlockUI
}




$(document).ready(function()
{
    jQuery("#selectbin").validationEngine('attach', {
        onValidationComplete: function(form, status){
            if(status){


                $.blockUI();
                $.post(
                    "TriggerMailServlet",
                    {
                        action: "loadSliderTable",
                        bin: $("#bin").val(),
                        mailgroup:$("#Grouplist").val()
                    },
                    function(data){
                        $("#showTable").html(data).hide().fadeIn('slow');
                    },
                    "html"

                    );







            }
        }
    });

   
                 
});